﻿#ifndef BLITER_UTIL_INCLUDE
#define BLITER_UTIL_INCLUDE

   //#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"   
    #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"

    TEXTURE2D(_BlitTexture);
    SAMPLER(sampler_BlitTexture);
    float4 _BlitTexture_TexelSize;
    
    #define SampleBlitTexture_float(uv,color) SampleBlitTexture(uv,color)
    #define SampleBlitTexture_half(uv,color) SampleBlitTexture(uv,color)
   
    void SampleBlitTexture(in real2 uv, out real4 color)
    {
        UnityTexture2D tex = UnityBuildTexture2DStructNoScale(_BlitTexture);
        color = SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv));
    }
    
    #define BlurBlitTexture_float(uv,uvOffset,color) BlurBlitTexture(uv,uvOffset,color)
    #define BlurBlitTexture_half(uv,uvOffset,color)  BlurBlitTexture(uv,uvOffset,color)

    void BlurBlitTexture(in real2 uv, in real2 uvOffset, out real4 color)
    {
        float3 weights = float3(0.147761, 0.118318, 0.0947416);
        UnityTexture2D tex = UnityBuildTexture2DStructNoScale(_BlitTexture);
        float2 uv0 = uv;
        color = SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv0)) * weights.x;
        
        uv0 = uv + float2(uvOffset.x, 0);
        color += SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv0)) * weights.y;
        uv0 = uv + float2(-uvOffset.x, 0);
        color += SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv0)) * weights.y;
        uv0 = uv + float2(0, uvOffset.y);
        color += SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv0)) * weights.y;
        uv0 = uv + float2(0, -uvOffset.y);
        color += SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv0)) * weights.y;

        uv0 = uv + float2(uvOffset.x, uvOffset.y);
        color += SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv0)) * weights.z;
        uv0 = uv + float2(-uvOffset.x, -uvOffset.y);
        color += SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv0)) * weights.z;
        uv0 = uv + float2(-uvOffset.x, uvOffset.y);
        color += SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv0)) * weights.z;
        uv0 = uv + float2(uvOffset.x, -uvOffset.y);
        color += SAMPLE_TEXTURE2D(tex.tex, tex.samplerstate, tex.GetTransformedUV(uv0)) * weights.z;
    }

#endif